package top.oneit.jdownload.data.dao;

import org.hibernate.Session;
import top.oneit.jdownload.data.entity.DownloadHistory;

import java.util.List;

/**
 * @author lingkang
 * @date 2021/12/5
 */
public class DownloadHistoryDao extends BaseDao {

    public static List<DownloadHistory> getHistory() {
        return getHistory(1);
    }

    public static List<DownloadHistory> getHistory(int size) {
        Session session = getSession();
        session.beginTransaction();
        List<DownloadHistory> list = session.createQuery("select distinct d from DownloadHistory d order by d.createTime desc")
                .setMaxResults(size)
                .list();
        session.getTransaction().commit();
        return list;
    }

}
